package com.app.view;

import android.content.Context;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created Date 2019/6/10
 *
 * @author liangkun
 * description：音乐--歌手 item适配器
 */
public class DemoRvAdapter extends RecyclerView.Adapter<DemoRvAdapter.SingleHolder> {
    private List<String> musicList; //数据
    private Context context; //上下文

    public DemoRvAdapter(Context context, List<String> musicList) {
        this.musicList = musicList;
        this.context = context;
    }


    @NonNull
    @Override
    public SingleHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View stortView = View.inflate(parent.getContext(), R.layout.music_singer_item, null);
        return new SingleHolder(stortView);

    }

    @Override
    public void onBindViewHolder(@NonNull SingleHolder holder, int position) {
        if (musicList != null) {
            if (musicList.size() > 0) {
                if(holder.tvSinger!=null){

                    holder.tvSinger.setText(musicList.get(position));
                }
            }
        }


    }


    @Override
    public int getItemCount() {
        if (musicList == null) {
            return 0;
        }
        return musicList.size();
    }


    class SingleHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_card_singer)
        ImageView ivSinger; //歌手图片
        @BindView(R.id.iv_more)
        ImageView ivMore; //更多
        @BindView(R.id.tv_singer)
        TextView tvSinger;
        @BindView(R.id.tv_singer_count)
        TextView tvCount;

        private SingleHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
